<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of base_report
 *
 * @author faroq
 */
class base_report extends MY_Controller {

    //put your code here
    public function __construct() {
        parent::__construct();
        $this->load->model('base_model', 'bm');
        $this->load->library('../controllers/global_reference');
    }

    public function getthbl($thbl) {
        $th = substr($thbl, 0, 4);
        $bl = substr($thbl, 4, 6);
        if ($bl == '01')
            $bl = 'Januari';
        else if ($bl == '02')
            $bl = 'Februari';
        else if ($bl == '03')
            $bl = 'Maret';
        else if ($bl == '04')
            $bl = 'April';
        else if ($bl == '05')
            $bl = 'Mei';
        else if ($bl == '06')
            $bl = 'Juni';
        else if ($bl == '07')
            $bl = 'Juli';
        else if ($bl == '08')
            $bl = 'Agustus';
        else if ($bl == '09')
            $bl = 'September';
        else if ($bl == '10')
            $bl = 'Oktober';
        else if ($bl == '11')
            $bl = 'Nopember';
        else if ($bl == '12')
            $bl = 'Desember';
        return $bl . ' ' . $th;
    }

    public function daftar_siswa_rows() {
        $page = ($this->input->post('page', TRUE) ? $this->input->post('page', TRUE) : 1);
        $start = isset($_POST['start']) ? $this->db->escape_str($this->input->post('start', TRUE)) : 0;
        $limit = isset($_POST['limit']) ? $this->db->escape_str($this->input->post('limit', TRUE)) : $this->config->item("length_records");
        $search = isset($_POST['query']) ? $this->db->escape_str($this->input->post('query', TRUE)) : '';
        $kelas = isset($_POST['kelas']) ? $this->db->escape_str($this->input->post('kelas', TRUE)) : '';
        $alumni = isset($_POST['alumni']) ? $this->db->escape_str($this->input->post('alumni', TRUE)) : '';
        $where = '';
        if ($kelas) {
            $where = "kd_kelas = '" . $kelas . "'";
        }
        $wherealumni = '';
        if ($alumni == 'all') {
            $wherealumni = '';
        }
        if ($alumni == 'aktif') {
            $wherealumni = "th_alumni is null";
        }
        if ($alumni == 'alumni') {
            $wherealumni = "th_alumni is not null";
        }
        if ($wherealumni != '') {
            if ($where != '') {
                $where = $where . " and " . $wherealumni;
            } else {
                $where = $wherealumni;
            }
        }

        $result = $this->bm->daftar_siswa_rows($search, $where, $start, $limit);
        echo $result;
    }

//reporting
    public function daftar_siswa_aktif() {
        $kelas = isset($_GET['kelas']) ? $this->db->escape_str($this->input->get('kelas', TRUE)) : NULL;
//        $search=isset($_GET['query']) ? $this->db->escape_str($this->input->get('query', TRUE)) : NULL;
//        $alumni=isset($_GET['alumni']) ? $this->db->escape_str($this->input->get('alumni', TRUE)) : '';
        $where = 'th_alumni is null';
        if ($kelas) {
            $where .=" and kd_kelas = '" . $kelas . "'";
        }
        $result = $this->bm->daftar_siswa_print('', $where);
        if ($result) {
            $thajaran = $this->bm->get_thajaran_aktif();
        } else {
            echo 'Data Tidak ditemukan';
            return;
        }

        $profile = $this->global_reference->get_profile();
        $namasekolah = $profile[0]->nama_sekolah;
        $alamat = $profile[0]->alamat_sekolah;
        $path_url = parse_url($profile[0]->url_logo, PHP_URL_PATH);

        $arr = explode('/', $path_url);
        $urlllogo = '';
        for ($i = 0; $i < count($arr); $i++) {
            if ($i > 1) {
                $urlllogo.=$arr[$i];
                if ($i < count($arr) - 1) {
                    $urlllogo.='/';
                }
            }
        }
        $this->load->library('report_fpdf/DaftarSiswaPerkelas');
        $pdf = new DaftarSiswaPerkelas('P', 'mm', 'A4');
        $pdf->setUrlLogo($urlllogo);
        $pdf->setNamasekolah($namasekolah);
        $pdf->setAlamat($alamat);
        $pdf->setDataheader($thajaran[0]);
        $pdf->AliasNbPages();
        $pdf->SetMargins(5, 5, 5);
        $pdf->SetFont('Arial', '', 8);
        $pdf->create_pdf($result);
        $pdf->Output("printoutpdf", "I");
    }

    public function daftar_siswa_param() {
        $kelas = isset($_GET['kelas']) ? $this->db->escape_str($this->input->get('kelas', TRUE)) : NULL;
        $search = isset($_GET['query']) ? $this->db->escape_str($this->input->get('query', TRUE)) : NULL;
        $alumni = isset($_GET['alumni']) ? $this->db->escape_str($this->input->get('alumni', TRUE)) : '';
        $where = '';
        if ($kelas) {
            $where = "kd_kelas = '" . $kelas . "'";
        }
        $wherealumni = '';
        if ($alumni == 'all') {
            $wherealumni = '';
        }
        if ($alumni == 'aktif') {
            $wherealumni = "th_alumni is null";
        }
        if ($alumni == 'alumni') {
            $wherealumni = "th_alumni is not null";
        }
        if ($wherealumni != '') {
            if ($where != '') {
                $where = $where . " and " . $wherealumni;
            } else {
                $where = $wherealumni;
            }
        }
        $result = $this->bm->daftar_siswa_print($search, $where);
        $thajaran = array();
        if (count($result) == 0) {
            echo 'Data Tidak ditemukan';
            return;
        }

        $profile = $this->global_reference->get_profile();
        $namasekolah = $profile[0]->nama_sekolah;
        $alamat = $profile[0]->alamat_sekolah;
        $path_url = parse_url($profile[0]->url_logo, PHP_URL_PATH);

        $arr = explode('/', $path_url);
        $urlllogo = '';
        for ($i = 0; $i < count($arr); $i++) {
            if ($i > 1) {
                $urlllogo.=$arr[$i];
                if ($i < count($arr) - 1) {
                    $urlllogo.='/';
                }
            }
        }
        $this->load->library('report_fpdf/DaftarSiswaPerkelas');
        $pdf = new DaftarSiswaPerkelas('P', 'mm', 'A4');
        $pdf->setUrlLogo($urlllogo);
        $pdf->setNamasekolah($namasekolah);
        $pdf->setAlamat($alamat);
        $pdf->setDataheader($thajaran);
        $pdf->AliasNbPages();
        $pdf->SetMargins(5, 5, 5);
        $pdf->SetFont('Arial', '', 8);
        $pdf->create_pdf($result);
        $pdf->Output("printoutpdf", "I");
    }

    public function biaya_siswa_print() {
        $idthajaran = isset($_GET['thajaran']) ? $this->db->escape_str($this->input->get('thajaran', TRUE)) : NULL;
        $kelas = isset($_GET['kelas']) ? $this->db->escape_str($this->input->get('kelas', TRUE)) : NULL;
        $nis = isset($_GET['nis']) ? $this->db->escape_str($this->input->get('nis', TRUE)) : NULL;

        $where = '';
        if ($idthajaran) {
            $where = "id_th_ajaran = '" . $idthajaran . "'";
        }
        if ($kelas) {
            if ($kelas != '') {
                if ($where != '') {
                    $where .=" and kd_kelas = '" . $kelas . "'";
                } else {
                    $where = "kd_kelas = '" . $kelas . "'";
                    ;
                }
            }
        }
        if ($nis) {
            if ($nis != '') {
                if ($where != '') {
                    $where .=" and nis = '" . $nis . "'";
                } else {
                    $where = "nis = '" . $nis . "'";
                    ;
                }
            }
        }
        
        $result = $this->bm->biaya_siswa_print($where);        
        if (count($result) == 0) {
            echo 'Data Tidak Ditemukan';
            return;
        }

        $profile = $this->global_reference->get_profile();
        $namasekolah = $profile[0]->nama_sekolah;
        $alamat = $profile[0]->alamat_sekolah;
        $path_url = parse_url($profile[0]->url_logo, PHP_URL_PATH);

        $arr = explode('/', $path_url);
        $urlllogo = '';
        for ($i = 0; $i < count($arr); $i++) {
            if ($i > 1) {
                $urlllogo.=$arr[$i];
                if ($i < count($arr) - 1) {
                    $urlllogo.='/';
                }
            }
        }
        $thajaran = $this->global_reference->get_thajaran($idthajaran);


        $this->load->library('report_fpdf/BiayaSiswa');
        $pdf = new BiayaSiswa('P', 'mm', 'A4');
        $pdf->setUrlLogo($urlllogo);
        $pdf->setNamasekolah($namasekolah);
        $pdf->setAlamat($alamat);
        $pdf->setDataheader($thajaran[0]);
        $pdf->AliasNbPages();
        $pdf->SetMargins(5, 5, 5);
        $pdf->SetFont('Arial', '', 8);
        $pdf->create_pdf($result);
        $pdf->Output("printoutpdf", "I");
    }
    
    public function potongan_print() {
        $thbl = isset($_GET['thbl']) ? $this->db->escape_str($this->input->get('thbl', TRUE)) : NULL;        
        $nis = isset($_GET['nis']) ? $this->db->escape_str($this->input->get('nis', TRUE)) : NULL;
        $paramreport='';
        $where = '';
        if ($thbl) {
            $where = "thbl_mulai <= $thbl and thbl_selesai >= $thbl";
            $paramreport="Tahun Bulan Periode = ".$this->getthbl($thbl);
        }
        
        if ($nis) {
            if ($nis != '') {
                if ($where != '') {
                    $where .=" and nis = '" . $nis . "'";
                } else {
                    $where = "nis = '" . $nis . "'";
                    ;
                }
                $paramreport .=" / NIS = $nis";
            }
        }
        
        $result = $this->bm->potongan_print($where);        
        if (count($result) == 0) {
            echo 'Data Tidak Ditemukan';
            return;
        }

        $profile = $this->global_reference->get_profile();
        $namasekolah = $profile[0]->nama_sekolah;
        $alamat = $profile[0]->alamat_sekolah;
        $path_url = parse_url($profile[0]->url_logo, PHP_URL_PATH);

        $arr = explode('/', $path_url);
        $urlllogo = '';
        for ($i = 0; $i < count($arr); $i++) {
            if ($i > 1) {
                $urlllogo.=$arr[$i];
                if ($i < count($arr) - 1) {
                    $urlllogo.='/';
                }
            }
        }
//        $thajaran = $this->global_reference->get_thajaran($idthajaran);
        $thajaran=array($paramreport);

        $this->load->library('report_fpdf/Potongan');
        $pdf = new Potongan('P', 'mm', 'A4');
        $pdf->setUrlLogo($urlllogo);
        $pdf->setNamasekolah($namasekolah);
        $pdf->setAlamat($alamat);
        $pdf->setDataheader($thajaran);
        $pdf->AliasNbPages();
        $pdf->SetMargins(5, 5, 5);
        $pdf->SetFont('Arial', '', 8);
        $pdf->create_pdf($result);
        $pdf->Output("printoutpdf", "I");
    }
    
    function set_message($kode,$msg){
        return '<script type="text/javascript" language="javascript">'
        .'set_message('.$kode.','.'"'.$msg.'");</script>';
    }
    
   

    public function saldopiutang_print() {
        $thbl = isset($_GET['thbl']) ? $this->db->escape_str($this->input->get('thbl', TRUE)) : NULL;        
        $nis = isset($_GET['nis']) ? $this->db->escape_str($this->input->get('nis', TRUE)) : NULL;
        $idthajaran = isset($_GET['idthajaran']) ? $this->db->escape_str($this->input->get('idthajaran', TRUE)) : NULL;
        $thajaran = isset($_GET['thajaran']) ? $this->db->escape_str($this->input->get('thajaran', TRUE)) : NULL;
        $kdkelas = isset($_GET['kelas']) ? $this->db->escape_str($this->input->get('kelas', TRUE)) : NULL;
        $idsemester = isset($_GET['idsemester']) ? $this->db->escape_str($this->input->get('idsemester', TRUE)) : NULL;
        $semester = isset($_GET['semester']) ? $this->db->escape_str($this->input->get('semester', TRUE)) : NULL;
        
        $paramreport='';
        $where = '';
        if ($idthajaran) {
            $where = "id_th_ajaran = '$idthajaran'";
            $paramreport="Tahun Ajaran $thajaran";            
        }else{
//            echo $this->set_message(1,'Tahun Ajaran Tidak Valid !!!') ;
            echo 'Tahun Ajaran Tidak Valid !!!';
            return;
        }
        
        if ($idsemester) {
            if (strlen($where)>0) {
                    $where .=" and semester = '$idsemester'";
                    $paramreport.=" - Semester $semester";
                } 
        }
        
        if ($thbl) {
            if (strlen($where)>0) {
                    $where .=" and thbl = '$thbl'";
                } 
        }
        if ($kdkelas) {
            if (strlen($where)>0) {
                    $where .=" and kd_kelas = '$kdkelas'";
                } 
        }
        
        if ($nis) {
            if (strlen($where)>0) {
                    $where .=" and nis = '$nis'";
                } 
        }
        
        $result = $this->bm->saldopiutang_print($where);        
        if (count($result) == 0) {
//            echo $this->set_message(1,'Data Tidak Ditemukan') ;
            echo 'Data Tidak Ditemukan';
            return;
        }

        $profile = $this->global_reference->get_profile();
        $namasekolah = $profile[0]->nama_sekolah;
        $alamat = $profile[0]->alamat_sekolah;
        $path_url = parse_url($profile[0]->url_logo, PHP_URL_PATH);

        $arr = explode('/', $path_url);
        $urlllogo = '';
        for ($i = 0; $i < count($arr); $i++) {
            if ($i > 1) {
                $urlllogo.=$arr[$i];
                if ($i < count($arr) - 1) {
                    $urlllogo.='/';
                }
            }
        }
        $total=0;
//        foreach ($result as $value) {
//            if($value->nis == '112233'){
//                $total++;
//                }
//        }
//        echo $total;
//        return;
//        $thajaran = $this->global_reference->get_thajaran($idthajaran);
        $thajaran=array($paramreport);

        $this->load->library('report_fpdf/SaldoPiutang');
        $pdf = new SaldoPiutang('P', 'mm', 'A4');
        $pdf->setUrlLogo($urlllogo);
        $pdf->setNamasekolah($namasekolah);
        $pdf->setAlamat($alamat);
        $pdf->setDataheader($thajaran);
        $pdf->AliasNbPages();
        $pdf->SetMargins(5, 5, 5);
        $pdf->SetFont('Arial', '', 8);
        $pdf->create_pdf($result);
        $pdf->Output("printoutpdf", "I");
    }
    
    public function saldopiutangrekap_print() {        
        $nis = isset($_GET['nis']) ? $this->db->escape_str($this->input->get('nis', TRUE)) : NULL;
        $paramreport='';
        if ($nis) {
            
                    $paramreport .=" NIS = '$nis'";
            
        }
//        $result=array();
        $result = $this->bm->SP_getData_array('rep_saldopiutang_rekap',array($nis)); 
        if (count($result) == 0) {
            echo 'Data Tidak Ditemukan';
            return;
        }
        $profile = $this->global_reference->get_profile();
        $namasekolah = $profile[0]->nama_sekolah;
        $alamat = $profile[0]->alamat_sekolah;
        $path_url = parse_url($profile[0]->url_logo, PHP_URL_PATH);

        $arr = explode('/', $path_url);
        $urlllogo = '';
        for ($i = 0; $i < count($arr); $i++) {
            if ($i > 1) {
                $urlllogo.=$arr[$i];
                if ($i < count($arr) - 1) {
                    $urlllogo.='/';
                }
            }
        }
        
        $thajaran=array($paramreport);

        $this->load->library('report_fpdf/SaldoPiutangRekap');
        $pdf = new SaldoPiutangRekap('P', 'mm', 'A4');
        $pdf->setUrlLogo($urlllogo);
        $pdf->setNamasekolah($namasekolah);
        $pdf->setAlamat($alamat);
        $pdf->setDataheader($thajaran);
        $pdf->AliasNbPages();
        $pdf->SetMargins(5, 5, 5);
        $pdf->SetFont('Arial', '', 8);
        $pdf->create_pdf($result);
        $pdf->Output("printoutpdf", "I");
        
    }
    public function payment_print() {
        $thblp = isset($_GET['thblp']) ? $this->db->escape_str($this->input->get('thblp', TRUE)) : NULL;        
        $thblb = isset($_GET['thblb']) ? $this->db->escape_str($this->input->get('thblb', TRUE)) : NULL;        
        $nis = isset($_GET['nis']) ? $this->db->escape_str($this->input->get('nis', TRUE)) : NULL;
        $idthajaran = isset($_GET['idthajaran']) ? $this->db->escape_str($this->input->get('idthajaran', TRUE)) : NULL;
        $thajaran = isset($_GET['thajaran']) ? $this->db->escape_str($this->input->get('thajaran', TRUE)) : NULL;
        $kdkelas = isset($_GET['kelas']) ? $this->db->escape_str($this->input->get('kelas', TRUE)) : NULL;
        $idsemester = isset($_GET['idsemester']) ? $this->db->escape_str($this->input->get('idsemester', TRUE)) : NULL;
        $semester = isset($_GET['semester']) ? $this->db->escape_str($this->input->get('semester', TRUE)) : NULL;
        $tglawal = isset($_GET['tglawal']) ? $this->db->escape_str($this->input->get('tglawal', TRUE)) : NULL;
        $tglakhir = isset($_GET['tglakhir']) ? $this->db->escape_str($this->input->get('tglakhir', TRUE)) : NULL;
        
//        echo $this->getthbl($tglakhir);
//        return;
        $paramreport='';
        $paramreport2='';
        $where = '';
        if ($idthajaran) {
            $where = 'id_th_ajaran = "'.$idthajaran.'"';
            $paramreport="Tahun Ajaran $thajaran";            
        }else{
//            echo $this->set_message(1,'Tahun Ajaran Tidak Valid !!!') ;
            echo 'Tahun Ajaran Tidak Valid !!!';
            return;
        }
        
        if ($idsemester) {
            if (strlen($where)>0) {
                    $where .=" and semester = '$idsemester'";
                    $paramreport.=" - Semester $semester";
                } 
        }
        
        if ($thblp) {
            if (strlen($where)>0) {
                    $where .=" and thbl = '$thblp'";
                    
                    $paramreport2="THBL Periode ".  $this->getthbl($thblp);  
                } 
        }
        if ($thblb) {
            if (strlen($where)>0) {
                    $where .=" and thblbayar = '$thblb'";
                    if (strlen($paramreport2)>0) {
                        $paramreport2.=" - THBL Bayar ".$this->getthbl($thblb); 
                    }else{
                        $paramreport2.="THBL Bayar ".$this->getthbl($thblb);  
                    }
                } 
        }
        if ($kdkelas) {
            if (strlen($where)>0) {
                    $where .=" and kd_kelas = '$kdkelas'";
                    if (strlen($paramreport2)>0) {
                        $paramreport2.=" - Kelas $kdkelas"; 
                    }else{
                        $paramreport2.="Kelas $kdkelas";  
                    }
                } 
        }
        
        if ($nis) {
            if (strlen($where)>0) {
                    $where .=" and nis = '$nis'";
                    if (strlen($paramreport2)>0) {
                        $paramreport2.=" - NIS $nis"; 
                    }else{
                        $paramreport2.="NIS $nis";  
                    }
                } 
        }
        if ($tglawal) {
            if ($tglakhir) {
                if (strlen($where)>0) {
                    $where .=" and (tglbayar between '$tglawal' and '$tglakhir')";
                    if (strlen($paramreport2)>0) {
                        $paramreport2.=" - TglBayar ".date('d F Y', strtotime($tglawal))." s/d ".date('d F Y', strtotime($tglakhir)); 
                    }else{
                        $paramreport2.="TglBayar ".date('d F Y', strtotime($tglawal))." s/d ".date('d F Y', strtotime($tglakhir));  
                    }
                } 
            }else{
                if (strlen($where)>0) {
                    $where .=" and tglbayar = '$tglawal'";
                    if (strlen($paramreport2)>0) {
                        $paramreport2.=" - TglBayar ". date('d F Y', strtotime($tglawal)); 
                    }else{
                        $paramreport2.="TglBayar ". date('d F Y', strtotime($tglawal)); 
                    }
                } 
            }
            
        }
        
        $result = $this->bm->payment_print($where);        
        if (count($result) == 0) {
//            echo $this->set_message(1,'Data Tidak Ditemukan') ;
            echo 'Data Tidak Ditemukan';
            return;
        }
//        else{
//            echo var_dump($result);
//            return;
//        }

        $profile = $this->global_reference->get_profile();
        $namasekolah = $profile[0]->nama_sekolah;
        $alamat = $profile[0]->alamat_sekolah;
        $path_url = parse_url($profile[0]->url_logo, PHP_URL_PATH);

        $arr = explode('/', $path_url);
        $urlllogo = '';
        for ($i = 0; $i < count($arr); $i++) {
            if ($i > 1) {
                $urlllogo.=$arr[$i];
                if ($i < count($arr) - 1) {
                    $urlllogo.='/';
                }
            }
        }
        $total=0;
//        foreach ($result as $value) {
//            if($value->nis == '112233'){
//                $total++;
//                }
//        }
//        echo $total;
//        return;
//        $thajaran = $this->global_reference->get_thajaran($idthajaran);
        $thajaran=array($paramreport,$paramreport2);

        $this->load->library('report_fpdf/Payment');
        $pdf = new Payment('P', 'mm', 'A4');
        $pdf->setUrlLogo($urlllogo);
        $pdf->setNamasekolah($namasekolah);
        $pdf->setAlamat($alamat);
        $pdf->setDataheader($thajaran);
        $pdf->AliasNbPages();
        $pdf->SetMargins(5, 5, 5);
        $pdf->SetFont('Arial', '', 8);
        $pdf->create_pdf($result);
        $pdf->Output("printoutpdf", "I");
    }
    
//    paymentrekap_print
    public function paymentrekap_print() {
        $thblp = isset($_GET['thblp']) ? $this->db->escape_str($this->input->get('thblp', TRUE)) : NULL;        
        $thblb = isset($_GET['thblb']) ? $this->db->escape_str($this->input->get('thblb', TRUE)) : NULL;        
        $rekening = isset($_GET['rekening']) ? $this->db->escape_str($this->input->get('rekening', TRUE)) : NULL;
        $idthajaran = isset($_GET['idthajaran']) ? $this->db->escape_str($this->input->get('idthajaran', TRUE)) : NULL;
        $thajaran = isset($_GET['thajaran']) ? $this->db->escape_str($this->input->get('thajaran', TRUE)) : NULL;        
        $idsemester = isset($_GET['idsemester']) ? $this->db->escape_str($this->input->get('idsemester', TRUE)) : NULL;
        $semester = isset($_GET['semester']) ? $this->db->escape_str($this->input->get('semester', TRUE)) : NULL;
        $tglawal = isset($_GET['tglawal']) ? $this->db->escape_str($this->input->get('tglawal', TRUE)) : NULL;
        $tglakhir = isset($_GET['tglakhir']) ? $this->db->escape_str($this->input->get('tglakhir', TRUE)) : NULL;
        $groupbysql = isset($_GET['groupby']) ? $this->db->escape_str($this->input->get('groupby', TRUE)) : NULL;
        
//        echo $this->getthbl($tglakhir);
//        return;
        $paramreport='';
        $paramreport2='';
        $where = '';
        if ($idthajaran) {
            $where = "id_th_ajaran = '$idthajaran'";
//            $where = "id_th_ajaran = '$idthajaran'";
            $paramreport="Tahun Ajaran $thajaran";            
        }else{
//            echo $this->set_message(1,'Tahun Ajaran Tidak Valid !!!') ;
            echo 'Tahun Ajaran Tidak Valid !!!';
            return;
        }
        
        if ($idsemester) {
            if (strlen($where)>0) {
                    $where .=" and semester = '$idsemester'";
                    $paramreport.=" - Semester $semester";
                } 
        }
        
        if ($thblp) {
            if (strlen($where)>0) {
                    $where .=" and thbl = '$thblp'";
                    
                    $paramreport2="TH/BLN Periode ".  $this->getthbl($thblp);  
                } 
        }
        if ($thblb) {
            if (strlen($where)>0) {
                    $where .=" and thblbayar = '$thblb'";
                    if (strlen($paramreport2)>0) {
                        $paramreport2.=" - TH/BLN Bayar ".$this->getthbl($thblb); 
                    }else{
                        $paramreport2.="TH/BLN Bayar ".$this->getthbl($thblb);  
                    }
                } 
        }        
        
        if ($rekening) {
            if (strlen($where)>0) {
                    $where .=" and no_rek = '$rekening'";
                    if (strlen($paramreport2)>0) {
                        $paramreport2.=" - REKENING $rekening"; 
                    }else{
                        $paramreport2.="REKENING $rekening";  
                    }
                } 
        }
        if ($tglawal) {
            if ($tglakhir) {
                if (strlen($where)>0) {
                    $where .=" and (tglbayar between '$tglawal' and '$tglakhir')";
                    if (strlen($paramreport2)>0) {
                        $paramreport2.=" - TanggalBayar ".date('d F Y', strtotime($tglawal))." s/d ".date('d F Y', strtotime($tglakhir)); 
                    }else{
                        $paramreport2.="TanggalBayar ".date('d F Y', strtotime($tglawal))." s/d ".date('d F Y', strtotime($tglakhir));  
                    }
                } 
            }else{
                if (strlen($where)>0) {
                    $where .=" and tglbayar = '$tglawal'";
                    if (strlen($paramreport2)>0) {
                        $paramreport2.=" - TanggalBayar ". date('d F Y', strtotime($tglawal)); 
                    }else{
                        $paramreport2.="TanggalBayar ". date('d F Y', strtotime($tglawal)); 
                    }
                } 
            }
            
        }
        if($groupbysql=='rekening'){
            $paramreport2.=" (Group Per".  ucwords($groupbysql).")";
        }
        if($groupbysql=='thbl'){
            $paramreport2.=" (Group Per".  ucwords('th/bln periode').")";
        }
        if($groupbysql=='thblbayar'){
            $paramreport2.=" (Group Per".  ucwords('th/bln bayar').")";
        }
        if($groupbysql=='tglbayar'){
            $paramreport2.=" (Group Per".  ucwords('tanggal bayar').")";
        }
        if($groupbysql=='jenis'){
            $paramreport2.=" (Group Per".  ucwords('jenis biaya').")";
        }
        
//        echo 'exec sp';
        $judul='';
        $result =array();
        if($groupbysql){
            $judul='REKAP PEMBAYARAN PIUTANG';
            $result = $this->bm->SP_getData_array('rep_piutangpay_rekap',array($where,$groupbysql));  
        }ELSE{
            $judul='DETAIL PEMBAYARAN PIUTANG';
            $result = $this->bm->SP_getData_array('rep_piutangpay_detail',array($where));  
        }
        
              
//        if (count($result) == 0) {
////            echo $this->set_message(1,'Data Tidak Ditemukan') ;
//            echo 'Data Tidak Ditemukan';
//            return;
//        }
//        else{
//            echo var_dump($result);
//            return;
//        }

        $profile = $this->global_reference->get_profile();
        $namasekolah = $profile[0]->nama_sekolah;
        $alamat = $profile[0]->alamat_sekolah;
        $path_url = parse_url($profile[0]->url_logo, PHP_URL_PATH);

        $arr = explode('/', $path_url);
        $urlllogo = '';
        for ($i = 0; $i < count($arr); $i++) {
            if ($i > 1) {
                $urlllogo.=$arr[$i];
                if ($i < count($arr) - 1) {
                    $urlllogo.='/';
                }
            }
        }        

        $thajaran=array($paramreport,$paramreport2);       

        $this->load->library('report_fpdf/PaymentRekap');
        $pdf = new PaymentRekap('P', 'mm', 'A4');
        $pdf->setUrlLogo($urlllogo);
        $pdf->setNamasekolah($namasekolah);
        $pdf->setAlamat($alamat);
        $pdf->setJudul($judul);
        $pdf->setDataheader($thajaran);
        $pdf->AliasNbPages();
        $pdf->SetMargins(5, 5, 5);
        $pdf->SetFont('Arial', '', 8);
        $pdf->create_pdf($result,$groupbysql);
        $pdf->Output("printoutpdf", "I");
    }
    
    public function testfpdf(){
        $judul='REKAP PEMBAYARAN PIUTANG';
        
        $profile = $this->global_reference->get_profile();
        $namasekolah = $profile[0]->nama_sekolah;
        $alamat = $profile[0]->alamat_sekolah;
        $path_url = parse_url($profile[0]->url_logo, PHP_URL_PATH);

        $arr = explode('/', $path_url);
        $urlllogo = '';
        for ($i = 0; $i < count($arr); $i++) {
            if ($i > 1) {
                $urlllogo.=$arr[$i];
                if ($i < count($arr) - 1) {
                    $urlllogo.='/';
                }
            }
        }   
        $result=array();
        for($k=0;$k<190;$k++){
            array_push($result, 'TEST '.$k) ;
        }
//        echo count($result);return;
        $thajaran=array('TEST H','TEST H1');   
        $this->load->library('report_fpdf/test_report');
        $pdf = new test_report('P', 'mm', 'A4');
        $pdf->setUrlLogo($urlllogo);
        $pdf->setNamasekolah($namasekolah);
        $pdf->setAlamat($alamat);
        $pdf->setJudul($judul);
        $pdf->setDataheader($thajaran);
        $pdf->AliasNbPages();
        $pdf->SetMargins(5, 5, 5);
        $pdf->SetFont('Arial', '', 8);
        $pdf->create_pdf($result);
        $pdf->Output("printoutpdf", "I");
    }
    public function testgen(){
        
        $k=  explode(',', 'no_rek,nama_rek,jenis_biaya,biaya,pelunasan');
        
//        echo var_dump(array_keys($k, 'jenis_biaya'));
//        return;
        
        $result = $this->bm->SP_getData_array('rep_piutangpay_rekap',array('','tglbayar')); 
        $where=array('tglbayar'=>'2014-04-17','no_rek'=>'1234567890');
        $arr1=array();
        foreach ($result as $value) {
            foreach ($value as $key => $v) {
                if(array_key_exists($key, $where)){                  
                        $arr1[$key]=$v;
                }                
            }
//            echo var_dump($where);
//            echo var_dump($arr1);
            $arr=array();
            $arr= array_intersect($arr1, $where);
            $arrdif=array();
            if(array_count_values($arr)==array_count_values($where)){
                echo var_dump($arr);
            }
//            echo 'differernt';
//            echo var_dump(array_count_values($arr));
//            echo var_dump(array_count_values($where));
//            echo '=====';
//            echo var_dump($arr);
            
        }
        return;
        foreach ($result as $value) {
            foreach ($value as $key => $v) {
                foreach($k as $kk){
                    if($kk==$key){
                        echo $v;
                    }
                }                
            }
            
            
        }
    }

}

?>
